<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<%@include file="../base/frameBase.jsp" %>
<body>
<table class="layui-hide" id="test" lay-filter="demo"></table>
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="agreeApply">通过</a>
  <a class="layui-btn layui-btn-xs" lay-event="disAgreeApply">拒绝</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delApply">删除申请记录</a>
</script>
 
<script>
var table;
layui.use(['table'], function(){
 table = layui.table;//表格
  //执行一个 table 实例
  table.render({
    elem: '#test'
    ,height: 332
    ,url: '${ctx}/userAuthData/getUserApplyList' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
        {field: 'userName', title: '申请人', width:150}
       ,{field: 'phoneNumber', title: '电话号码', width:180}
       ,{field: 'applyStatus', title: '审核状态', width:150,templet: function(item){
    	   if(item.applyStatus==1){
    		   return '<span style="color: #c00;">待审核</span>'
    	   }else if(item.applyStatus==2){
    		   return '<span style="color: green;">审核通过</span>'
    	   }else{
    		   return '<span style="color: #c00;">审核失败</span>'
    	   }
          
       }}
       ,{field: 'createTime', title: '申请时间', width:150}
       ,{field: 'handleTime', title: '处理时间', width:150}
       ,{field: 'comment', title: '处理意见', width:250}
      ,{fixed: 'right', title: '操作', width: 200, align:'center', toolbar: '#barDemo'}
    ]]
 	  , id: 'tableReload'
      , page: true
      , height: 500
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	  debugger;
   //1.同意2.拒绝3.删除
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    if(layEvent === 'agreeApply'){
    	operateApply(data.id,1);
    } else if(layEvent === 'disAgreeApply'){
    	operateApply(data.id,2);
    } else if(layEvent === 'delApply'){
    	  layer.confirm('真的删除行么', function(index){
    		  operateApply(data.id,3);
    	        obj.del(); //删除对应行（tr）的DOM结构
    	        layer.close(index);
    	        //向服务端发送删除指令
    	      });
    }
  });
  
});

function operateApply(applyId,operateType){
	debugger;
    // 发起请求删除课程
    $.ajax({
        url: '${ctx}/userAuthData/editUserApply?applyId='+applyId+'&operatorType='+operateType,
        method: 'POST',
        contentType: 'application/json',
        success: function (data) {
                layer.msg('审核成功！');
                // 刷新下视频数据表格
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                obj.del();
        },
        error: function (data) {
        	layer.msg("失败，请联系管理员");
        }
    })
}
</script>
</body>
</html>        
        
</body>
<%@include file="../base/frameFoot.jsp" %>